/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * UpdateClientDialog.java
 *
 * Created on 23.Eki.2010, 17:19:39
 */
package view.user;

import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import model.Campaign;
import model.Client;
import model.user.Staff;

/**
 *
 * @author CUNEYT
 */
public class UpdateClientDialog extends javax.swing.JDialog {

    private Client client = null;
    private Campaign campaign = null;
    private ArrayList<Staff> staff = null;

    public UpdateClientDialog(java.awt.Frame parent, boolean modal, Client c, Campaign cam, ArrayList<Staff> st) {
        this(parent, modal);
        client = c;
        campaign = cam;
        staff = st;
        clientNameTextField.setText(client.getName());
        clientInfoTextArea.setText(client.getGeneral_info());
        clientContactTextField.setText(client.getContact_info());
        clientContactPersonTextField.setText(client.getContact_person());
        responsibleStaffList.setModel(new ACIListModel(staff));

    }

    /** Creates new form UpdateClientDialog */
    public UpdateClientDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        clientNameTextField = new javax.swing.JTextField();
        clientContactTextField = new javax.swing.JTextField();
        clientContactPersonTextField = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        clientInfoTextArea = new javax.swing.JTextArea();
        cancelClientUpdateButton = new javax.swing.JButton();
        updateClientButton = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        responsibleStaffList = new javax.swing.JList();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("Name");

        jLabel2.setText("General Info");

        jLabel3.setText("Contact Info");

        jLabel4.setText("Contact Person");

        clientInfoTextArea.setColumns(20);
        clientInfoTextArea.setRows(5);
        jScrollPane1.setViewportView(clientInfoTextArea);

        cancelClientUpdateButton.setText("CANCEL");
        cancelClientUpdateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelClientUpdateButtonActionPerformed(evt);
            }
        });

        updateClientButton.setText("OK");
        updateClientButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateClientButtonActionPerformed(evt);
            }
        });

        responsibleStaffList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        responsibleStaffList.setVisibleRowCount(-1);
        jScrollPane2.setViewportView(responsibleStaffList);

        jLabel5.setText("RESPONSIBLE STAFF AT ACI");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(updateClientButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelClientUpdateButton))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addGap(65, 65, 65)
                            .addComponent(clientNameTextField))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(jLabel3)
                            .addGap(31, 31, 31)
                            .addComponent(clientContactTextField))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel4)
                                .addComponent(jLabel2))
                            .addGap(18, 18, 18)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(clientContactPersonTextField)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane2, 0, 0, Short.MAX_VALUE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(clientNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(clientContactTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(clientContactPersonTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelClientUpdateButton)
                    .addComponent(updateClientButton))
                .addContainerGap(36, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void updateClientButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateClientButtonActionPerformed

        try {
            if (!getClientNameTextField().getText().isEmpty()) {
                client.setName(getClientNameTextField().getText());
                client.setContact_info(getClientContactTextField().getText());
                client.setContact_person(getClientContactPersonTextField().getText());
                client.setGeneral_info(getClientInfoTextArea().getText());
                Staff s = (Staff) responsibleStaffList.getSelectedValue();
                if (s != null) {
                    campaign.setResponsible(s);
                    campaign.assignStaff(s);
                }
                dispose();
            } else {
                throw new Exception("Client name cannot be empty!");
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex);
        }

    }//GEN-LAST:event_updateClientButtonActionPerformed

    private void cancelClientUpdateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelClientUpdateButtonActionPerformed
        dispose();
    }//GEN-LAST:event_cancelClientUpdateButtonActionPerformed

    public JButton getCancelClientUpdateButton() {
        return cancelClientUpdateButton;
    }

    public JTextField getClientContactPersonTextField() {
        return clientContactPersonTextField;
    }

    public JTextField getClientContactTextField() {
        return clientContactTextField;
    }

    public JTextArea getClientInfoTextArea() {
        return clientInfoTextArea;
    }

    public JTextField getClientNameTextField() {
        return clientNameTextField;
    }

    public JButton getUpdateClientButton() {
        return updateClientButton;
    }

    public Campaign getCampaign() {
        return campaign;
    }

    public void setCampaign(Campaign campaign) {
        this.campaign = campaign;
    }

    public Client getClient() {
        return client;
    }

    public void setClient(Client client) {
        this.client = client;
    }

    public ArrayList<Staff> getStaff() {
        return staff;
    }

    public void setStaff(ArrayList<Staff> staff) {
        this.staff = staff;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelClientUpdateButton;
    private javax.swing.JTextField clientContactPersonTextField;
    private javax.swing.JTextField clientContactTextField;
    private javax.swing.JTextArea clientInfoTextArea;
    private javax.swing.JTextField clientNameTextField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JList responsibleStaffList;
    private javax.swing.JButton updateClientButton;
    // End of variables declaration//GEN-END:variables
}
